package controller;

public abstract class TimedGameControl extends GameControl {
	
	private long mLastPressedMs;
	
	private long mCooldown;
	
	public TimedGameControl(int keyCode, String id, String desc, long delay) {
		super(keyCode, id, desc);
		mCooldown = delay;
	}
	
	@Override
	public void execute(int keyCode) {
		long curTime = System.currentTimeMillis();
		
		long elapsed = curTime - mLastPressedMs;
		
		if (elapsed > mCooldown) {
			super.execute(keyCode);
			mLastPressedMs = curTime;
		}
		
		
	}
	
	public void setDelay(long delay) {
		mCooldown = delay;
	}

}
